;(function (w) {
	function getQueryString(name) {
	  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
	  var r = window.location.href.substr(window.location.href.indexOf('?') + 1).match(reg);
	  if (r != null) {
	    return unescape(r[2]);
	  }
	  return null;
	}
  //登录验证
  var token = Cookies.get("token")
	var userMes = w.localStorage.getItem('userMes') ? JSON.parse(w.localStorage.getItem('userMes')) : {}

	let str = `<div class="bill-pop dy-flex z-999" style="width: 100%;height: 100%;position: fixed;left: 0;top: 0;background-color: rgba(0,0,0,.5);justify-content: center;align-items: center;">
			<div style="width: 400px;background: #fff;" class="br-4 relative overflow">
				<h3 class="font-18 text-center" style="color:#565E99; padding-top: 20px;">登录超时</h3>
				<p class="font-14 text-center ptb-20">请关闭当前页面,重新打开</p>
				<div class="dy-flex line-height-45 text-center ptb-10 border-t">
					<button class="n-btn-primary br-4 js-window-close" style="margin:0 auto;">关闭</button>
				</div>
			</div>
		</div>`

  if (!token) {
		if (userMes.preSysCode == 'DEBI') {
			$(document.body).append(str)
			$('.fz-content').remove()

			$('.js-window-close').on('click', function () {
				window.close();
				window.location.href="about:blank";
			})
			return
		}
    if (!getQueryString('corp_type')) {
			w.location.href = '/login.html'
		}
  }

  // 获取用户对应的第三方平台类型
  hlhttp.get({
    url:'user/corp_info',
    success:function(data){
      var userMes = window.localStorage.getItem('userMes') ? JSON.parse(window.localStorage.getItem('userMes')) : {}
      userMes['corpConfigFlag'] = data.corpConfigFlag;
      window.localStorage.setItem('userMes',JSON.stringify(userMes));
    }
  })

  // 用户信息

  if (userMes) {
    $('.js-user').text(userMes.name)
  }
  // 退出
  $('.js-logout').click(function() {
    Cookies.remove('token')
    w.localStorage.clear()
    w.location.href = 'login.html'
  })

  $('.show-hide-children-slide').mouseenter(function(){
      $('.normal-user').show()

    var oauthType = JSON.parse(window.localStorage.getItem('userMes')).oauthType;
    var isAdmin = JSON.parse(window.localStorage.getItem('userMes')).isAdmin;

    if(oauthType == 'WX' || oauthType == 'DD_AND_WX'){
      $('.normal-user').show()
      $('.dd-user').hide()
	  return
    }

    if(oauthType == 'DD'){
      if(isAdmin == 'Y'){
        $('.admin-user-btn').hide()
        $('.normal-user-btn').show()
      }
      if(isAdmin == 'N'){
        $('.admin-user-btn').show()
        $('.normal-user-btn').hide()
      }

      $('.normal-user').hide()
      $('.dd-user').show()
    }
  })

  $('.logout-cr').mouseleave(function(){
    $('.normal-user').hide()
    $('.dd-user').hide()
  })

  //弹出修改密码框
  $('.xg-pw').click(function(event) {
    $('.changepassword-wrap').removeClass('hidden')
  });
  //取消修改密码
  $('.js-login-cl,.pw-close').click(function() {
    $('.changepassword-wrap').addClass('hidden')
    $('.int-pw input').val('')
  });
  // 切换为管理员用户
  $('.admin-user-btn').click(function(){
    window.location.href = 'ddAdminLogin.html'
    window.localStorage.clear()
    window.sessionStorage.clear()
  })
  // 切换为普通用户
  $('.normal-user-btn').click(function(){
    window.location.href = 'ddlogin.html?normalUser'
    window.localStorage.clear()
    window.sessionStorage.clear()
  })

  //验证密码
  var flag;
  $('.js-newpw,.js-newpw1').focus(function(event) {
    flag = false;
  });
  $('.js-newpw,.js-newpw1,.js-oldpw').blur(function () {
    if ($(this).val().trim()) {
      if ($(this).val().trim().length < 6) {
        hl.toast('密码不能小于6位')
        flag = true;
      }
    }
  })
  $('.js-newpw1').blur(function () {
    if (flag) return
    if ($(this).val().trim() !== $('.js-newpw').val().trim()) {
      hl.toast('新密码俩次输入的不一致')
      flag = true;
    }
  })
  //提交新密码
  $('.js-login-qs').unbind().on('click', function () {
    if (flag) return;
    var sflag = false;
    if (!$('.js-oldpw').val().trim()) sflag = true;
    if (!$('.js-newpw').val().trim()) sflag = true;
    if (!$('.js-newpw1').val().trim()) sflag = true;
    if (sflag) {
      hl.toast('密码不能为空')
      return
    }
    hlhttp.put({
      url: 'user/password',
      data: {
        oldpasswd: $('.js-oldpw').val().trim(),
        newpasswd1: $('.js-newpw').val().trim(),
        newpasswd2: $('.js-newpw1').val().trim()
      },
      success: function () {
        hl.toast('修改密码成功')
        $('.changepassword-wrap').addClass('hidden')
        $('.int-pw input').val('')
        Cookies.remove('token')
        w.localStorage.clear()
        w.location.href = 'login.html'
      }
    })
  })
}(window))
